--- title: Title keywords: fastai sidebar: home_sidebar nb_path: "05b05 Test Swiss Roll with New Kernel (7-11).ipynb" ---
from directed_graphs.datasets import directed_circle, directed_cylinder, directed_spiral, directed_swiss_roll, directed_spiral_uniform, directed_swiss_roll_uniform
from directed_graphs.datasets import plot_directed_2d, plot_directed_3d
from directed_graphs.diffusion_flow_embedding import DiffusionFlowEmbedder
import torch
import numpy as np
if torch.__version__[:4] == "1.13":
# device = torch.device('cuda' if torch.cuda.is_available() else 'mps' if torch.has_mps else 'cpu')
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
else:
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
device
X, flow, labels = directed_swiss_roll_uniform(num_nodes=1000, num_spirals=2.5, radius=1, height=20, xtilt=0, ytilt=0)
plot_directed_3d(X, flow, labels, mask_prob=0.5)
X = torch.tensor(X)
flow = torch.tensor(flow)
X = X.float().to(device)
flow = flow.float().to(device)
dfe = DiffusionFlowEmbedder(X,flow,t=1,sigma_graph=5,sigma_embedding=5,device=device, learning_rate = 1e-3)
dfe = dfe.to(device)
embeddings = dfe.fit(n_steps=2000)
dfe.visualize_points(labels)
dfe2 = DiffusionFlowEmbedder(X,flow,t=1,
sigma_graph=5,sigma_embedding=5,device=device,
learning_rate = 1e-3, smoothness = 0, weight_of_flow = 1)
dfe2 = dfe2.to(device)
embeddings = dfe2.fit(n_steps=2000)
dfe2.visualize_points(labels)
X, flow, labels = directed_swiss_roll_uniform(num_nodes=1000, num_spirals=2.5, radius=5, height=5, xtilt=0, ytilt=0)
plot_directed_3d(X, flow, labels, mask_prob=0.5)
X = torch.tensor(X)
flow = torch.tensor(flow)
X = X.float().to(device)
flow = flow.float().to(device)
dfe3 = DiffusionFlowEmbedder(X,flow,t=1,
sigma_graph=10,sigma_embedding=10,device=device,
learning_rate = 1e-3, smoothness = 0, weight_of_flow = 1)
dfe3 = dfe3.to(device)
embeddings = dfe3.fit(n_steps=2000)
dfe3.visualize_points(labels)
import phate
import matplotlib.pyplot as plt
X, flow, labels = directed_swiss_roll_uniform(num_nodes=1000, num_spirals=2.5, radius=5, height=5, xtilt=0, ytilt=0)
plot_directed_3d(X, flow, labels, mask_prob=0.5)
phate_operator = phate.PHATE(n_components = 2, knn=5, decay=20, t=150)
phate_op = phate.PHATE()
data_phate = phate_op.fit_transform(X)
phate.plot.scatter2d(data_phate, c=labels)